﻿@inherits RazorFunction

@functions {
    public override string FunctionDescription
    {
        get { return "Shows a statement decorated with large icons"; }
    }

    private const string iconWidget = @"
    <f:widgetfunction xmlns:f=""http://www.composite.net/ns/function/1.0"" name=""Composite.Widgets.String.FontIconSelector"">
		<f:param name=""ClassNameOptions"">
			<f:function name=""Widgets.FontIconSelector.GetIconsNames"" />
		</f:param>
		<f:param name=""StylesheetPath"" value=""~/Frontend/Styles/font-awesome/font-awesome.css"" />
		<f:param name=""ClassNamePrefix"" value=""fa fa-"" />
	</f:widgetfunction>";

    [FunctionParameter(Label = "Icon", Help = "The icon to show on top of the statement", DefaultValue = null, WidgetMarkup = iconWidget)]
    /* widget defined below */
    public string Icon { get; set; }

    [FunctionParameter(Label = "Image", Help = "The image to show on top of the statement if Icon is not selected", DefaultValue = null)]
    public DataReference<IImageFile> Image { get; set; }

    [FunctionParameter(Label = "Heading", Help = "The heading of the statement", DefaultValue = null)]
    public string Heading { get; set; }

    [FunctionParameter(Label = "Statement", Help = "The statement to show.", DefaultValue = null, WidgetFunctionName = "Composite.Widgets.String.TextArea")]
    public string Statement { get; set; }

    [FunctionParameter(Label = "Link", Help = "If you want the statement to link to another page, specify the link here.", DefaultValue = null, WidgetFunctionName = "Composite.Widgets.String.UrlComboBox")]
    public string Link { get; set; }

}

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://www.composite.net/ns/function/1.0">
<head>
</head>
<body>
    <div class="page-block page-block-iconified">
        @if (string.IsNullOrWhiteSpace(Link))
        {
            @StatementBody()}
        else
        {
            <a href="@Link">@StatementBody()</a>
        }
    </div>
</body>

</html>
@helper StatementBody()
{
    var isIcon = !string.IsNullOrEmpty(Icon);
    var isImage = Image != null;
    if (isImage || isIcon)
    {
        <span class="@(isIcon ? "page-block-icon" : "page-block-img")">
            @if (isIcon)
            {
                <span class="icon-helper"></span>
                <span class="icon fa fa-@Icon"></span>
            }
            else
            {
                <img class="img-responsive" alt="@Heading" src="@Html.C1().MediaUrl(Image.Data.Id.ToString())?mw=900" />
            }

        </span>
    }
    <h3 class="page-block-header">@Heading</h3>
    <div class="page-block-body">
        @foreach (var statementBlock in Statement.Split(Environment.NewLine.ToCharArray()).Where(f => f.Length > 0))
        {
            <p>@statementBlock</p>
        }
    </div>
}

